//
//  ServiceCell.m
//  mendianjieke
//
//  Created by 响当当 on 7/31/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//


#import "ServiceCell.h"
#import "CustomerInfoViewController.h"

@interface ServiceCell()
@property (nonatomic, strong)UIImageView *headImageView;//头像
@property (nonatomic, strong)UIButton *checkAttackButton;//查看攻略
@property (nonatomic, strong)UIButton *overButton;//立即结束
@end

@implementation ServiceCell

- (UIImageView *)headImageView
{
    if (!_headImageView)
    {
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(25*kUIScaleBasePlus,17*kUIScaleBasePlus,150*kUIScaleBasePlus,150*kUIScaleBasePlus)];
        _headImageView.layer.cornerRadius = 4;
    }
    return _headImageView;
}

- (UIButton *)checkAttackButton
{
    if (!_checkAttackButton)
    {
        _checkAttackButton = [Utilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+30*kUIScaleBasePlus,30*kUIScaleBasePlus,125*kUIScaleBasePlus, 50*kUIScaleBasePlus)
                                               textAligment:UIControlContentHorizontalAlignmentCenter
                                                       text:@"查看攻略"
                                                   textClor:LCHexColor(0xFFFFFF)
                                                  buttonBGC:LCHexColor(0xFF7A17)
                                                   textFont:17*kUIScaleBasePlus
                                                     target:self
                                                     method:@selector(checkAttackClick)];
        _checkAttackButton.layer.masksToBounds = YES;
        _checkAttackButton.layer.cornerRadius = 4;
    }
    return _checkAttackButton;
}

- (UIButton *)overButton
{
    if (!_overButton)
    {
        _overButton = [Utilties creatButtonWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+30*kUIScaleBasePlus,CGRectGetMaxY(self.checkAttackButton.frame)+20*kUIScaleBasePlus,125*kUIScaleBasePlus, 50*kUIScaleBasePlus)
                                               textAligment:UIControlContentHorizontalAlignmentCenter
                                                       text:@"立即结束"
                                                   textClor:LCHexColor(0xFFFFFF)
                                                  buttonBGC:LCHexColor(0x989898)
                                                   textFont:17*kUIScaleBasePlus
                                                     target:self
                                                     method:@selector(overButtonClick)];
        _overButton.layer.masksToBounds = YES;
        _overButton.layer.cornerRadius = 4;
    }
    return _overButton;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.headImageView];
        [self.contentView addSubview:self.checkAttackButton];
        [self.contentView addSubview:self.overButton];
    }
    return self;
}

#pragma mark - Method
- (void)checkAttackClick
{
    CustomerInfoViewController *vc = [[CustomerInfoViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    vc.customerID = self.model.customerId;
    [[Utilties getCurrentVC].navigationController pushViewController:vc animated:YES];
}

- (void)overButtonClick
{
    NSDictionary *pramaters = @{
                                @"id" : self.model.customerId,
                                @"operate" : @"2"
                                };
    
    WeakSelf(self)
    [infoManager cancelCustomer:pramaters sucess:^(id  _Nonnull acceptData) {
        NSNumber *num = acceptData[@"data"];
        if (num.integerValue == 0)
        {
            if (weakSelf.serviceLockBlock)
            {
                weakSelf.serviceLockBlock();
            }
        }
    } fail:^(NSError * _Nullable error) {
        
    }];
}

- (void)setModel:(RealTimeModel *)model
{
    _model = model;
    
    NSArray *arr = [model.photo componentsSeparatedByString:@","];
    
    NSData *decodeData = [[NSData alloc]initWithBase64EncodedString:arr[1] options:(NSDataBase64DecodingIgnoreUnknownCharacters)];
    self.headImageView.image = [UIImage imageWithData:decodeData];
}
@end
